﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class MiniMapScreenShot : MonoBehaviour
{
    public Camera camera;

    public RenderTexture rt;

    public Material mat;

    public void ScreenShot()
    {
        var path = "Assets/ResourcesAssets/Pve/Textures/pveMiniMap0.png";
        #if UNITY_EDITOR
        RenderTexture rt = new RenderTexture(1334,750,24);
        camera.targetTexture = rt;
        RenderTexture.active = rt;
        camera.Render();
        Texture2D png = new Texture2D(rt.width,rt.height,TextureFormat.ARGB32,false);
        png.ReadPixels(new Rect(0,0,rt.width,rt.height),0,0);
        png.Apply();
        camera.targetTexture = null;
        RenderTexture.active = null;
        byte[] bytes = png.EncodeToPNG();
        FileStream file = File.Open(path, FileMode.OpenOrCreate);
        BinaryWriter writer = new BinaryWriter(file);
        writer.Write(bytes);
        file.Close();
        Texture2D.DestroyImmediate(png);
        png = null;
        #endif
    }
}
